function ismobile() {
    //判断访问终端
    var browser = {
        versions: function () {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
                weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
                qq: u.match(/\sQQ/i) == " qq" //是否QQ
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };
    if (browser.versions.mobile == true) {
        if (browser.versions.iPhone == true) {
            return '1';
        } else if (browser.versions.android == true) {
            return '0';
        }
    } else {

    }
};

var a = ismobile();

//$(function () {

var goods_id, page, size, params;

//    getId();
//
//
//});


function getId() {

    if (a == 1) {

        CallManPowerEvaluationModel.jsCallOCWithSendId();

    } else if (a == 0) {

        window.android.getAndroidId("okok");
    }

}

if (a == 0) {

    window.android.getAndroidId("okok");
}

function WebViewDidFinishLoad() {

    var message = {

        "VcWay": "SendId"
    };

    window.webkit.messageHandlers.CallManPowerEvaluationModel.postMessage(message);
}

function receive_android_projectid(k) {

    //alert(JSON.stringify(k))

    var obj = $.parseJSON(k);

    //console.log(obj)

    goods_id = obj.goods_id;

    page = 1;

    size = 10;

    params = new Params(1, goods_id, size, 100);

    //console.log(params)


    mescroll.resetUpScroll()
}

function receiveiOSVcData(i) {

    var obj = $.parseJSON(i);

    goods_id = obj.goods_id;

    page = 1;

    size = 10;

    params = new Params(1, goods_id, size, 100);

    mescroll.resetUpScroll()
}

function Params(page, goods_id, size, port) {

    this.page = page;

    this.goods_id = goods_id;

    this.size = size;

    this.port = port
}

//创建MeScroll对象
var mescroll = new MeScroll("mescroll", {

    down: {

        auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true; (注: down的callback默认调用 mescroll.resetUpScroll(); )

        //callback: function (mescroll) {

        //    mescroll.resetUpScroll(); //下拉刷新的回调,默认重置上拉加载列表为第一页

        //}

        clearEmptyId: "dataList",

        callback: downCallback

    },

    up: {

        clearEmptyId: "dataList",

        noMoreSize: 5,

        auto: false, //是否在初始化时以上拉加载的方式自动加载第一页数据; 默认false

        isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10

        callback: upCallback, //上拉回调,此处可简写; 相当于 callback: function (page) { upCallback(page); }

        empty: {

            //icon: "../person_home/img/wallet_img_no@3x.png", //图标,默认null

            tip: "暂无相关评价", //提示
        }
    }
});

function downCallback() {

    //联网加载数据

    //var params=new Params(0,1,10);

    //console.log(params)

    params.page = 0;

    params.size = 0;

    getListDataFromNet(params, function (data) {

        //联网成功的回调,隐藏下拉刷新的状态

        mescroll.endSuccess();

        //设置列表数据

        if (data.codes == 200) {

            var list = data.data.list;

            mescroll.endBySize(list.length, data.data.totalCount); //必传参数(当前页的数据个数, 总数据量)

            setListData(data);


            $(".appraiseLength").html(data.data.totalCount);

        } else {

            mescroll.endBySize(0, 0);

            //$(".mescroll-empty").css("display", "none");

            mescroll.showEmpty();

        }
    }, function () {

        //联网失败的回调,隐藏下拉刷新的状态

        mescroll.endErr();
    });
}
/*上拉加载的回调 page = {num:1, size:10}; num:当前页 从1开始, size:每页数据条数 */

function upCallback(page) {

    //var params = new Params(0, 1, 10);

    //console.log(params)

    params.page = page.num;

    params.size = page.size;


    getListDataFromNet(params, function (data) {

        if (data.codes == 200) {

            var list = data.data.list;

            mescroll.endBySize(list.length, data.data.totalCount); //必传参数(当前页的数据个数, 总数据量)

            setListData(data);

            $(".appraiseLength").html(data.data.totalCount);

        } else {

            mescroll.endBySize(0, 0);

            $(".appraiseLength").html(0);

            //$(".mescroll-empty").css("display", "none");

            mescroll.showEmpty();
        }
    }, function () {

        mescroll.endErr();
    });
}

/*设置列表数据*/

function setListData(data) {


    data.data.list.forEach(function (item, i) {

        item.created = timeFormat(item.created_at * 1000);
    });

    var html = template("appraiseTpl1", data);

    $("#mescroll ul").append(html);

    if (isiphoneX) {

        $(".footer_position").addClass("footer");

        $(".mescroll").css("padding-bottom", "0.484rem")
    } else {

        $(".footer_position").removeClass("footer");

    }
}


function getListDataFromNet(params, successCallback, errorCallback) {

    $.ajax({

        type: "POST",

        url: url + "users/commentlist",

        dataType: "json",

        data: params,

        success: function (data) {

            //alert(JSON.stringify(data))

            //console.log(data);

            successCallback(data)

        },

        error: errorCallback

    });

}

function timeFormat(timestamp) {

    //timestamp是整数，否则要parseInt转换,不会出现少个0的情况

    var time = new Date(timestamp);

    var year = time.getFullYear();

    var month = time.getMonth() + 1;

    return year + '年' + month + '月';
}
//mescroll.resetUpScroll();